<template>
  <div class="container">
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <!-- form表单引入 -->
        <el-form :model="dialogForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户ID" prop="id">
                <el-input v-model="dialogForm.id"></el-input>
            </el-form-item>
            <el-form-item label="微信昵称" prop="name">
                <el-input v-model="dialogForm.name" ></el-input>
            </el-form-item>
            <el-form-item label="会员手机" prop="phone">
                <el-input v-model="dialogForm.phone"></el-input>
            </el-form-item>
            <el-form-item label="消费金额" prop="money">
                <el-input v-model.number="dialogForm.money"></el-input>
            </el-form-item>
            <el-form-item label="订单数量" prop="num">
                <el-input v-model.number="dialogForm.num"></el-input>
            </el-form-item>
            <el-form-item label="会员等级" prop="type">
                <el-select v-model="dialogForm.type" placeholder="请选择会员等级">
                    <el-option value="0"></el-option>
                    <el-option value="1"></el-option>
                    <el-option value="2"></el-option>
                    <el-option value="3"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="上次消费时间" prop="paytime">
                <el-input v-model="dialogForm.paytime"></el-input>
            </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button @click="closeParentFun">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </span>
      </el-dialog>

  </div>
</template>

<script>
import {updateStuApi} from '../../../api/stuApi'
export default {
    props:['dialogRow'],
    data() {
      return {
        dialogVisible: true,
        dialogForm: {
          id:'',          //用户ID
          name:'', //微信昵称
          phone:'',     //会员手机
          money:'',       //消费金额
          num:'',              //订单数量
          type:'',                //会员等级
          paytime:'',//上次消费时间
        },
        rules: {
          name: [
            { required: true, message: '请输入微信昵称', trigger: 'blur' },
            { min: 2, max: 8, message: '长度在 2 到 8 个字符', trigger: 'blur' }
          ],
          id: [
            { required: true, message: '请输入用户ID', trigger: 'blur' }
          ],
          phone: [
            {  required: true, message: '请输入会员手机', trigger: 'blur' }
          ],
          money: [
            {  required: true, message: '请输入消费金额', trigger: 'blur' }
          ],
          num: [
            { required: true, message: '请输入订单数量', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '请选择会员等级', trigger: 'change' }
          ],
          paytime: [
            { required: true, message: '请输入上次消费时间', trigger: 'blur' }
          ]
        }
      };
    },
    mounted(){
      // this.dialogForm = JSON.parse(JSON.stringify(this.dialogRow))//深拷贝
      // this.dialogForm = {...this.dialogRow}//浅拷贝
      this.dialogForm = Object.assign({},this.dialogRow)//浅拷贝 优先使用浅拷贝，速度更快



    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {//修改
            //打包数据 发送请求 后台数据修改 通知前端 关闭弹框 刷新表格
            updateStuApi(this.dialogForm).then(res=>{
              console.log(res);
              if(res.code == 200){
                this.$parent.isShow = false //关闭弹窗
                this.$emit('resettablefun') //刷新表格 
              }
            })
                
            } else {
                console.log('error submit!!');
                return false;
            }
            })
        },
        closeParentFun(){
            this.$parent.isShow = false
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
            .then(_ => {
                done();
                this.$parent.isShow = false
            })
            .catch(_ => {});
        }
    }

}
</script>

<style scoped>
/* .container{

} */
</style>